﻿<%@ Page Language="C#" MasterPageFile="~/Master.Master" AutoEventWireup="true" CodeBehind="PS_TimeAttendants.aspx.cs" Inherits="KPIS.GERP.GHRMS.APP.App_UI.Forms.PS_TimeAttendants" %>

<%@ Register src="../Controls/user.ascx" tagname="user" tagprefix="uc3" %>

<asp:Content ID="Content1" runat="server" contentplaceholderid="ContentPlaceHolder1">
    
    <link href="../../Styles/CssClass.css" rel="stylesheet" type="text/css" />
    <title>บันทึกเวลาปฏิบัติงาน / ขาด / ลา / มาสาย</title>
    
    <telerik:RadCodeBlock ID="RadCodeBlock2" runat="server">        
            <script type="text/javascript">
                function onTextChange(sender) {
                    if (sender.get_value() == "") {
                        sender.set_text("");
                    }
                }                  
                function UseRadWindow1() {
                    var oWnd = $find("<%= windowAutoAssign.ClientID %>");
                    oWnd.show();
                    //oWnd.setSize(400, 400);
                    oWnd.setUrl("/App_UI/Forms/PS_TimeAttendantsAutoAssign.aspx");  
                }

                function getSourceFile() {
                    extArray = new Array(".txt");
                    allowSubmit = false;
                    var file = document.getElementById('<%= attachment.ClientID %>');
                    var source_file = document.getElementById('<%= hdSourceFile.ClientID %>');
                    var div_part = document.getElementById('<%= uploadFile_div.ClientID %>');
                    value = file.value;
                    if (value.length == 0) {
                        return;
                    }
                    while (value.indexOf("\\") != -1) {
                        value = value.slice(value.indexOf("\\") + 1);
                    }
                    ext = value.slice(value.indexOf(".")).toLowerCase();
                    for (var i = 0; i < extArray.length; i++) {
                        if (ext.indexOf(extArray[i]) >= 0) {
                            allowSubmit = true; 
                            break;
                        }
                    }
                    if (allowSubmit) {
                        source_file.value = file.value;
                    }
                    else {
                        alert("ไฟล์เอกสารใช้ได้เฉพาะนามสกุล .txt เท่านั้น");
                        div_part.innerHTML = div_part.innerHTML;
                        file.value = null;
                        source_file.value = null;
                    }
                }
                
                function chkTxt() {
                    var file = document.getElementById('<%= attachment.ClientID %>');
                    value = file.value;
                    if (value.length == 0) {
                        alert("กรุณาเลือกไฟล์!");
                        return false;
                    }
                }

                function MessageAlert(strMessageAlert) {
                    window.alert(strMessageAlert);
                }

                Sys.Application.add_load(setCalendarDateWorkingTable);
                function setCalendarDateWorkingTable() {
                    var tooltip = $find("<%= ToolTipDateWorking.ClientID %>");
                    var calendar = $find("<%= CalendarDateWorking.ClientID %>");
                    var fastNavigation = calendar._getFastNavigation();
                    fastNavigation.OnToday =
                        function() {
                            var today = new Date;
                            var date = [today.getFullYear(), today.getMonth() + 1, today.getDate()];
                            calendar.selectDate(date, true);
                            fastNavigation.Popup.Hide();
                            var all_date = date.toString().split(",");
                            var year = parseInt(all_date[0]) + 543;
                            var month = all_date[1];
                            var day = all_date[2];
                            if (day.length == 1) {
                                day = '0' + day;
                            }
                            if (month.length == 1) {
                                month = '0' + month;
                            }

                            var maskText = $find("<%= txtDateWorking.ClientID %>");
                            maskText.set_value(day + month + year);
                            tooltip.hide();
                        }
                }
                function OnDateWorkingClick(calendarInstance, args) {
                    var tooltip = $find("<%= ToolTipDateWorking.ClientID %>");
                    var fastNavigation = calendarInstance._getFastNavigation();
                    var date = args.get_renderDay().get_date().toString();
                    var all_date = date.split(",");
                    var year = parseInt(all_date[0]) + 543;
                    var month = all_date[1];
                    var day = all_date[2];
                    if (day.length == 1) {
                        day = '0' + day;
                    }
                    if (month.length == 1) {
                        month = '0' + month;
                    }

                    var maskText = $find("<%= txtDateWorking.ClientID %>");
                    maskText.set_value(day + month + year);
                    tooltip.hide();
                }
                function OnCalendarDateWorkingViewChanged(sender, step) {
                    var year = parseInt(sender.FocusedDate[0]) + 543;
                    var month = sender.FocusedDate[1];
                    document.getElementById("CalendarDateWorking_Title").innerHTML = changeMonthNumberToName(month) + " " + year;
                }

            </script>
        
    </telerik:RadCodeBlock>
    
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="RadGrid2">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid2" LoadingPanelID="RadAjaxLoadingPanel2" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>

    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel2" runat="server">
    </telerik:RadAjaxLoadingPanel>
    
    <asp:HiddenField ID="hdSourceFile" runat="server" Value="" />    
   
    <telerik:RadWindowManager ID="RadWindowManager1" runat="server">
        <Windows>
            <telerik:RadWindow ID="windowAutoAssign" runat="server" Height="300px" style="display:none;" Width="600px">
            </telerik:RadWindow>
        </Windows>
        
    </telerik:RadWindowManager>
    
    <asp:Panel ID="Panel6" runat="server" CssClass="contentPanelPaddingTop5px">
        <div class="Background980V2" >
            <table width="100%" cellpadding="0" cellspacing="0">
                <tr>
                    <td align="right">ประเภทบุคลากร :
                    </td>
                    <td>
                        <telerik:RadComboBox
                            ID="cmbEmpType"
                            DataTextField="Name"
                            DataValueField="Sequence"
                            AllowCustomText="true"
                            runat="server"
                            Width="200px"
                            Filter="Contains"
                            AutoPostBack="True"
                            CausesValidation="false"
                            ValidationGroup="EmpType"
                            EmptyMessage="... เลือกประเภทบุคลากร ..."
                            OnSelectedIndexChanged="cmbEmpType_SelectedIndexChanged">
                        </telerik:RadComboBox>
                    </td>
                    <td align="right">หน่วยงาน :
                    </td>
                    <td>
                        <telerik:RadComboBox
                            ID="cmbWorkingJobSite"
                            DataTextField="job_site_name"
                            DataValueField="job_site_seq"
                            AllowCustomText="true"
                            runat="server"
                            Width="200px"
                            Filter="Contains"
                            EmptyMessage="... เลือกสังกัด ..."
                            OnClientTextChange="onTextChange"
                            OnSelectedIndexChanged="cmbWorkingJobSite_SelectedIndexChanged">
                        </telerik:RadComboBox>
                    </td>
                    <td align="right">วันที่ :
                    </td>
                    <td>
                        <telerik:RadMaskedTextBox ID="txtDateWorking" runat="server" Mask=" ##/##/####" Width="75px"
                            TextWithLiterals=" //" SelectionOnFocus="SelectAll">
                        </telerik:RadMaskedTextBox>
                        <asp:LinkButton ID="LinkButton4" runat="server" CssClass="LinkButton">
                            <img alt="" src="../Images/Buttons/Calendar.gif" style="border:0px;vertical-align:middle;" />
                        </asp:LinkButton>
                        <telerik:RadToolTip ID="ToolTipDateWorking" runat="server"
                            Animation="None" HideEvent="LeaveToolTip"
                            Position="MiddleRight" ShowEvent="OnClick" Skin="Telerik"
                            TargetControlID="LinkButton4" Modal="true">
                            <telerik:RadCalendar ID="CalendarDateWorking" runat="server"
                                TitleFormat="MMMM yyyy"
                                EnableMultiSelect="false"
                                UseRowHeadersAsSelectors="false"
                                UseColumnHeadersAsSelectors="false"
                                DayCellToolTipFormat="dddd, dd MMMM, yyyy"
                                NavigationPrevToolTip="เดือนก่อนหน้า"
                                NavigationNextToolTip="เดือนถัดไป"
                                FastNavigationNextToolTip="3 เดือนถัดไป"
                                FastNavigationPrevToolTip="3 เดือนก่อนหน้า">
                                <ClientEvents OnDateClick="OnDateWorkingClick"
                                    OnCalendarViewChanged="OnCalendarDateWorkingViewChanged"></ClientEvents>
                                <FastNavigationSettings EnableTodayButtonSelection="true"
                                    TodayButtonCaption="ไปที่วันนี้"
                                    OkButtonCaption="เปลี่ยน"
                                    CancelButtonCaption="ยกเลิก" />
                            </telerik:RadCalendar>
                        </telerik:RadToolTip>
                    </td>
                    <td>
                        <asp:LinkButton ID="btnImport" runat="server" CssClass="LinkButton">
                            <img style="border:0px;vertical-align:middle;" alt="คลิกที่นี่เพื่อนำเข้าข้อมูลจากระบบ Scan" 
                            src="../Images/Buttons/backup.gif" />&nbsp;&nbsp;นำเข้าข้อมูล
                        </asp:LinkButton>
                    </td>
                    <td>
                        <a href="javascript:UseRadWindow1();" class="LinkButton" title="ใส่ข้อมูลการมาทำงานอัตโนมัติ ตามเวลาปกติ">ใส่ข้อมูลอัตโนมัติ</a>
                    </td>
                </tr>
                <tr>
                    <td colspan="7">
                        <telerik:RadToolTip runat="server" ID="RadToolTip2" Width="500px" Height="100px"
                            TargetControlID="btnImport" ShowEvent="OnClick"
                            IsClientID="false" Animation="Fade"
                            Position="BottomRight" Skin="Default" Modal="true" ManualClose="true">
                            <table align="center" width="500px">
                                <br />
                                <tr>
                                    <td align="right">ที่อยู่ไฟล์ : </td>
                                    <td align="left">
                                        <div id="uploadFile_div" runat="server">
                                            <input id="attachment" runat="server" name="attachment" onchange="getSourceFile();"
                                                onkeydown="return false;" size="90" type="file" style="width: 400px" />
                                            &#160;
                                            <label id="Label11" runat="server"></label>
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <asp:Button ID="btnLoad" runat="server" Height="20px" Text="Upload..."
                                            OnClientClick="return chkTxt();" OnClick="btnLoad_Click" />
                                    </td>
                                </tr>
                            </table>
                        </telerik:RadToolTip>
                    </td>
                </tr>
            </table>
        </div>
        <table align="center" width="1000px">
            <tr>
                <td align="left" class="tableHeader">ข้อมูลเวลาการปฏิบัติราชการ </td>
            </tr>
            <tr>
                <td>
                    <asp:Panel ID="Panel4" runat="server">
                        <telerik:RadGrid ID="RadGrid1" runat="server"
                            AllowAutomaticDeletes="True"
                            AllowFilteringByColumn="True" AllowMultiRowEdit="True"
                            AllowMultiRowSelection="True" AllowPaging="True" AllowSorting="True"
                            AutoGenerateColumns="False" EnableAJAX="True"
                            EnableAJAXLoadingTemplate="True"
                            GridLines="None" Width="998px"
                            OnItemCommand="RadGrid1_ItemCommand" Skin="Outlook">
                            <MasterTableView AllowMultiColumnSorting="True" CellSpacing="-1"
                                CommandItemDisplay="Top" DataKeyNames="working_seq"
                                InsertItemPageIndexAction="ShowItemOnCurrentPage"
                                NoMasterRecordsText="&lt; ไม่มีข้อมูล &gt;">
                                <CommandItemTemplate>
                                    <table width="100%">
                                        <tr>
                                            <td>
                                                <asp:LinkButton ID="cmdAddNew" runat="server"
                                                    CausesValidation="False" CommandName="InitInsert"
                                                    Visible="<%# !RadGrid1.MasterTableView.IsItemInserted && RadGrid1.EditIndexes.Count <= 0 %>"> <img alt="" src="../Images/Buttons/AddRecord.gif" 
                                                                style="border:0px;vertical-align:middle;" /> เพิ่มข้อมูลใหม่
                                                </asp:LinkButton>&#160;&#160; 
                                            </td>
                                            <td align="right"></td>
                                        </tr>
                                    </table>
                                </CommandItemTemplate>
                                <RowIndicatorColumn>
                                    <HeaderStyle Width="20px" />
                                </RowIndicatorColumn>
                                <ExpandCollapseColumn Visible="True">
                                </ExpandCollapseColumn>
                                <GroupByExpressions>
                                    <telerik:GridGroupByExpression>
                                        <GroupByFields>
                                            <telerik:GridGroupByField FieldName="job_site_name"
                                                HeaderText="สังกัด" />
                                        </GroupByFields>
                                        <SelectFields>
                                            <telerik:GridGroupByField FieldName="job_site_name"
                                                HeaderText="สังกัด" />
                                        </SelectFields>
                                    </telerik:GridGroupByExpression>
                                    <telerik:GridGroupByExpression>
                                        <GroupByFields>
                                            <telerik:GridGroupByField FieldName="working_date"
                                                FormatString="{0:dd/MM/yyyy}" HeaderText="วันที่" />
                                        </GroupByFields>
                                        <SelectFields>
                                            <telerik:GridGroupByField FieldName="working_date"
                                                FormatString="{0:dd/MM/yyyy}" HeaderText="วันที่" />
                                        </SelectFields>
                                    </telerik:GridGroupByExpression>
                                </GroupByExpressions>
                                <Columns>
                                    <telerik:GridEditCommandColumn ButtonType="ImageButton"
                                        EditText="คลิกเพื่อแก้ไขรายการ"
                                        ItemStyle-Width="15">
                                        <ItemStyle Width="15px" />
                                    </telerik:GridEditCommandColumn>
                                    <telerik:GridButtonColumn ButtonType="ImageButton"
                                        CommandName="Delete"
                                        ConfirmDialogType="RadWindow" ConfirmText="ลบข้อมูลที่เลือก?"
                                        ItemStyle-Width="15" Text="คลิกเพื่อลบรายการ" UniqueName="column1">
                                        <ItemStyle Width="15px" />
                                    </telerik:GridButtonColumn>
                                    <telerik:GridBoundColumn AutoPostBackOnFilter="true"
                                        DataField="emp_name"
                                        FilterControlWidth="100%"
                                        HeaderStyle-HorizontalAlign="Center"
                                        HeaderText="ชื่อ - นามสกุล"
                                        ShowFilterIcon="false"
                                        UniqueName="emp_name">
                                        <HeaderStyle HorizontalAlign="Center" />
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn AutoPostBackOnFilter="true"
                                        DataField="pos_ref"
                                        FilterControlWidth="100%"
                                        HeaderStyle-HorizontalAlign="Center"
                                        HeaderText="เลขที่ตำแหน่ง"
                                        ShowFilterIcon="false" UniqueName="pos_ref">
                                        <HeaderStyle HorizontalAlign="Center" Width="50px" />
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn AutoPostBackOnFilter="true" DataField="pos_name"
                                        FilterControlWidth="100%" HeaderStyle-HorizontalAlign="Center"
                                        HeaderText="ชื่อตำแหน่งในสายงาน" ShowFilterIcon="false" UniqueName="pos_name">
                                        <HeaderStyle HorizontalAlign="Center" Width="200px" />
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn AutoPostBackOnFilter="true" DataField="class_name"
                                        FilterControlWidth="100%" HeaderStyle-HorizontalAlign="Center"
                                        HeaderText="ระดับตำแหน่ง" ShowFilterIcon="false" UniqueName="class_name">
                                        <HeaderStyle HorizontalAlign="Center" Width="100px" />
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn AutoPostBackOnFilter="true" DataField="working_start"
                                        FilterControlWidth="100%" HeaderStyle-HorizontalAlign="Center"
                                        HeaderText="เวลาเข้า" ShowFilterIcon="false" UniqueName="working_start">
                                        <HeaderStyle HorizontalAlign="Center" Width="50px" />
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn AutoPostBackOnFilter="true" DataField="working_end"
                                        FilterControlWidth="100%" HeaderStyle-HorizontalAlign="Center"
                                        HeaderText="เวลาออก" ShowFilterIcon="false" UniqueName="working_end">
                                        <HeaderStyle HorizontalAlign="Center" Width="50px" />
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn AutoPostBackOnFilter="true"
                                        DataField="working_status_descr" FilterControlWidth="100%"
                                        HeaderStyle-HorizontalAlign="Center" HeaderText="สถานะการปฏิบัติงาน"
                                        ShowFilterIcon="false" UniqueName="working_status_descr" Visible="False">
                                        <HeaderStyle HorizontalAlign="Center" Width="100px" />
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="remarks"
                                        HeaderStyle-HorizontalAlign="Center" HeaderText="หมายเหตุ" UniqueName="remarks"
                                        Visible="false">
                                        <HeaderStyle HorizontalAlign="Center" Width="100px" />
                                    </telerik:GridBoundColumn>
                                </Columns>
                                <EditFormSettings EditFormType="WebUserControl" UserControlName="../UserControls/PS_TimeAttendants.ascx">
                                    <EditColumn UniqueName="EditCommandColumn1">
                                    </EditColumn>
                                </EditFormSettings>
                                <PagerStyle Mode="NextPrevNumericAndAdvanced" />
                            </MasterTableView>
                            <ClientSettings AllowColumnHide="True" AllowColumnsReorder="True"
                                EnableRowHoverStyle="True" ReorderColumnsOnClient="True">
                                <Selecting AllowRowSelect="True" EnableDragToSelectRows="true" />
                            </ClientSettings>
                        </telerik:RadGrid>
                    </asp:Panel>
                </td>
            </tr>
        </table>
    </asp:Panel> 
</asp:Content>
